package com.careercup.question.id5765470632280064;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Solution {
	/**
	 * You are given a matrix. Starting from [0, 0], you have to move over the matrix in clockwise-spiral direction, i.e., we start from [0, 0], move upto [0, 4], and then move to [3, 4], then move to [3, 0], then move to [1, 0], then to [1, 3] and so on. 
	 * Move in this way and print all the elements.
	 * Input :
	 * 1 2 3 4 5
	 * 6 8 9 a b
	 * c d e  f g
	 * h  i  j  k l
	 * Output :
	 * 1 2 3 4 5 b g l k j i h c 6 8 9 a f e d
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		List<String> l = new ArrayList<String>();
		while(in.hasNext())
			l.add(in.next());
		int lb = 0, rb = l.get(0).length(), ub = 1, db = l.size(), cr = 0, cc = 0;
		while(true) {
			if(cc >= rb)
				break;
			while(cc < rb)
				System.out.print(l.get(cr).charAt(cc++));
			cc--;
			rb--;
			cr++;
			if(cr >= db)
				break;
			while(cr < db)
				System.out.print(l.get(cr++).charAt(cc));
			cr--;
			db--;
			cc--;
			if(cc < lb)
				break;
			while(cc >= lb)
				System.out.print(l.get(cr).charAt(cc--));
			cc++;
			lb++;
			cr--;
			if(cr < ub)
				break;
			while(cr >= ub)
				System.out.print(l.get(cr--).charAt(cc));
			cr++;
			ub++;
			cc++;
		}
		System.out.println();
	}
}
